package acom.dhy.qigsaw2test

import android.content.pm.PackageManager
import androidx.core.app.ComponentActivity
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class ResourceInjectedTest {
    @Test
    fun useAppContext() {
        val application = InstrumentationRegistry.getInstrumentation().targetContext
        val info = application.packageManager.getPackageInfo(application.packageName, PackageManager.GET_ACTIVITIES)
        val classLoader = application.classLoader
        val needInject: MutableSet<String> = mutableSetOf()
        info.activities.forEach {
            try {
                val a = classLoader.loadClass(it.name)
                if (!ComponentActivity::class.java.isAssignableFrom(a)) {
                    needInject.add(it.name)
                }
            } catch (e: Exception) {
                println("${e.javaClass.simpleName} >>>>>>>>>>>>>>>>>>> ${it.name}")
            }
        }
        needInject.forEach {
            println("not ComponentActivity -> $it")
        }
    }
}